<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>违规记录修改</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      padding: 0;
    }
    .container {
      width: 300px;
      margin: 100px auto;
      padding: 20px;
      background: #fff;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    h2 {
      text-align: center;
      color: #333;
    }
    form {
      display: flex;
      flex-direction: column;
    }
    label {
      margin-bottom: 5px;
      color: #555;
    }
    input[type="text"],
    input[type="datetime-local"],
    textarea,
    input[type="submit"] {
      padding: 10px;
      margin-bottom: 15px;
      border: 1px solid #ddd;
      border-radius: 4px;
    }
    input[type="submit"] {
      background-color: #28a745;
      color: white;
      border: none;
      cursor: pointer;
    }
    input[type="submit"]:hover {
      background-color: #218838;
    }
  </style>
</head>
<body>
<div class="container">
  <h2>违规记录修改</h2>
  <form id="modifyRecordForm">
    <label for="recordId">记录ID:</label>
    <input type="text" id="recordId" name="recordId" required>

    <label for="residentId">居民ID:</label>
    <input type="text" id="residentId" name="residentId" required>

    <label for="description">违规描述:</label>
    <textarea id="description" name="description" required></textarea>

    <label for="time">违规时间:</label>
    <input type="datetime-local" id="time" name="time" required>

    <label for="location">违规地点:</label>
    <input type="text" id="location" name="location" required>

    <label for="result">处理结果:</label>
    <textarea id="result" name="result" required></textarea>

    <input type="submit" value="修改记录">
  </form>
</div>

<script>
  document.getElementById('modifyRecordForm').addEventListener('submit', function(event) {
    event.preventDefault();
    const formData = new FormData(this);
    const data = {
      vrId: formData.get('recordId'),
      vrResidentId: formData.get('residentId'),
      vrDescription: formData.get('description'),
      vrTime: formData.get('time'),
      vrLocation: formData.get('location'),
      vrResult: formData.get('result')
    };

    fetch('http://localhost:8081/waste/api/violation/update', {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    })
            .then(response => response.json())
            .then(data => {
              if (data.success) {
                alert('违规记录修改成功！');
              } else {
                alert('修改失败，请检查输入信息！');
              }
            })
            .catch(error => {
              alert('修改失败，请检查网络连接！');
              console.error('Error:', error);
            });
  });
</script>
</body>
</html>